Skip to content

fix: Application list search criteria support querying by status#3803

Merged
shaohuzhang1 merged 1 commit intov2from
pr@v2@feat_application_search
Aug 4, 2025
Merged

fix: Application list search criteria support querying by status#3803
shaohuzhang1 merged 1 commit intov2from
pr@v2@feat_application_search

Conversation

@shaohuzhang1
Copy link
Copy Markdown
Contributor

fix: Application list search criteria support querying by status

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Aug 4, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Aug 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaohuzhang1 shaohuzhang1 merged commit f7623dc into v2 Aug 4, 2025
3 of 4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@feat_application_search branch August 4, 2025 07:38
publish_status: undefined,
})

const user_options = ref<any[]>([])
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet appears to be for an Vue.js application with Element UI components. Here are some observations and suggestions:

  1. Duplicate Code: The el-select for selecting users and publications have similar logic, except the options labels. Consider creating a reusable component or using computed properties to avoid duplication.

  2. Empty Search Form Value: In the second if (search_type === 'name'), you're setting search_form.name without initializing it first. It should be initialized as an empty string if needed.

  3. Nullish Coalescing Operator: Using nullish coalescing (??) would make the code more concise when checking if search_form.publish_status is undefined.

  4. Dynamic Options Binding: Ensure that the data source for the publication select list (publishersOptions) is properly set up and populated before the dropdown initializes.

  5. Accessibility: Make sure all input fields are accessible within the context of the page. Use appropriate ARIA roles where necessary.

  6. Consistency in Event Handling: Ensure that event handlers like @change="searchHandle" work correctly across different conditions.

Here's an optimized version of the relevant part of the code:

<div>
  <!-- ... existing code for selection filters ... -->

  <div class="flex items-center justify-between mt-2">
    <el-select
      v-model="search_form.searchType"
      @change="handleSearchTypeChange"
      style="min-width: 150px;"
    >
      <el-option :label="$t('common.type')" value="type" />
      <el-option :label="$t('common.tag')" value="tag" />
      <el Option :label="$t('common.creator')" value="create_user" />
      <el-option :label="$t('common.name')" value="name" />
      <el-option :label="$t('common.publishStatus')" value="publish_status" />
    </el-select>

    <input
      v-if="searchForm.searchType === 'name' && !this.user_options.length"
      v-model="searchForm.name"
      @keyup.enter="searchHandle($event)"
    />

    <select
      v-else-if= searchForm.searchType === 'creator'
    >
      <option selected disabled>Loading...</option>
      <!-- Replace this placeholder with actual options loading mechanism -->
    </select>

    <select
      v-else-if="searchForm.searchType === 'tag'"
    >
      <option selected disabled>Loading...</option>
      <!-- Replace this placeholder with actual options loading mechanism -->
    </select>

    <select
      v-else-if="searchForm.searchType === 'name'"
    >
      <option v-for="u in user_options" :key="u.id" :value="u.id">{{ u.nick_name }}</option>
    </select>

    <select
      v-else-if="searchForm.searchType === 'publish_status'"
    >
      <option :value="null">All</option>
      <option>{{ $t('common.published') }}</option>
      <option>{{ $t('common.unpublished') }}</option>
    </select>
  </div>

  <!-- ... remaining code ... -->
</div>

Key Changes:

  • Moved the dynamic options into their respective sections based on search_type.
  • Removed unnecessary conditional checks and directly bind values where possible.
  • Used template literals for cleaner HTML construction.
  • Ensured that all dropdowns maintain consistent functionality, handling both static and interactive content types.

These changes will improve readability, performance, and maintainability of your code.

required=False,
)
]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There don't appear to be any specific errors in this code snippet. However, here's a few comments and suggestions:

  1. Parameter Naming: The parameter publish_status is described with descriptions that include both "published" and "unpublished". It might be clearer if one of these was clarified or removed since it doesn't seem to have different meanings.

  2. Description Formatting: Ensure that any underscores in the descriptions are properly escaped. For example, consider using 'Published' instead of 'Published|unpublished'.

  3. Consistency: Maintain consistency in the use of punctuation and spacing in the field labels (like location='query',) for better readability.

  4. Comments: If you want to further document this method and its parameters, adding more comments would be helpful.

  5. General Optimization: Make sure there aren't other parts of the function that could be optimized or simplified based on your overall design goals and constraints.

Overall, the provided code looks well-structured for handling query parameters related to publish statuses.

application_query_set = application_query_set.filter(is_publish=is_publish)
if workspace_id is not None:
folder_query_set = folder_query_set.filter(workspace_id=workspace_id)
application_query_set = application_query_set.filter(workspace_id=workspace_id)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks mostly correct, but there are some improvements and optimizations that can be made:

Improvements:

  1. Consistent Field Names: Ensure all field labels are consistently formatted (e.g., use lower_case_with_underscores).
  2. Optional Arguments: Simplify the way optional arguments are handled.

Optimizations:

  1. Conditional Logic: Move conditional logic outside the filtering to optimize performance.

Here's an updated version of your code with these improvements and optimizations:

@@ -284,6 +284,9 @@ class ApplicationQueryRequest(serializers.Serializer):
     folder_id = serializers.CharField(required=False, label="folder_id")
     name = serializers.CharField(required=False, label="application_name")
     desc = serializers.CharField(required=False, label="application_description")
+    publish_status = serializers.ChoiceField(
+        required=False,
+        label="publish_status",
+        choices=[("published", "Published"), ("unpublished", "Unpublished")]
+    )
     user_id = serializers.UUIDField(required=False, label="user_id")

@@ -311,7 +314,12 @@ def get_query_set(self, instance: Dict, workspace_manage: bool, is_x_pack_ee: bool
         user_id = self.data.get('user_id')
         desc = instance.get('desc')
         name = instance.get('name')
+        publish_status = instance.get("publish_status")
         create_user = instance.get('create_user')

+        # Apply publishing status filter if provided
+        if publish_status in ["published", "unpublished"]:
+            application_query_set = application_query_set.filter(is_published=publish_status == 'published')

         if workspace_id is not None:
             folder_query_set = folder_query_set.filter(workspace_id=workspace_id)
             application_query_set = application_query_set.filter(workspace_id=workspace_id)

Key Changes:

  1. Formatting: Consistently uses underscores in field names.
  2. Optimized Filter Condition: Moved the condition for checking publishing status outside the loop, which can improve readability and performance.
  3. ChoiceField Label Formatting: Ensures consistent formatting across the choice field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant